<!DOCTYPE html>
<html lang="en">
<head>
    <!--
    @Author 硕鼠
    @Date 2020/4/7 11:58
    @Version 1.0
    @Description offsetParent
  -->
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1 {width: 200px;height: 200px;background: #CCC;position: relative}
        #div2 {width: 100px;height: 100px;background: red;position: absolute}
    </style>
    <script>
        //div2相对于div1进行定位
        window.onload = function () {
            var oDiv = document.getElementById("div2");
            alert(oDiv.offsetParent);
        };
    </script>
</head>
<body>

    <div id="div1">
        <div id="div2"></div>
    </div>
</body>
</html>